import { createStore } from 'vuex'

export default createStore({
  state: {
    //zxy:更新了一种储存全局变量的方法，使用localStorage存在本地可以保证刷新或跳转这个值不改变（因为没法只定义不赋值，刷新会变成最开始的）
    user_name:localStorage.userName,
    own_door:localStorage.own_door,
    userID:localStorage.userID,
    userEmail:localStorage.userEmail,
    my_portal_id:localStorage.my_portal_id,
    portal_id:localStorage.portal_id,
    //是否登录，是为true，否!=true（不一定为false）
    isLogin:localStorage.isLogin,
    isCompany:localStorage.isCompany,
  },
  mutations: {
    updateown_door(state, payload) {
      state.own_door = payload
      localStorage.setItem('own_door', payload)
    },
    updateUserName(state, payload) {
      state.user_name = payload
      //zxy:在这里set到本地
      localStorage.setItem('userName', payload)
    },
    updateUserID(state, payload) {
      state.userID = payload
      localStorage.setItem('userID', payload)
    },
    updateUserEmail(state, payload) {
      state.userEmail = payload
      localStorage.setItem('userEmail', payload)
    },
    updateMPID(state, payload) {
      state.my_portal_id = payload
      localStorage.setItem('my_portal_id', payload)
    },
    updatePID(state, payload) {
      state.portal_id = payload
      localStorage.setItem('portal_id', payload)
    },
    updateIsLogin(state, payload) {
      state.isLogin = payload
      localStorage.setItem('isLogin', payload)
    },
    updateIsCompany(state, payload) {
      state.isCompany = payload
      localStorage.setItem('isCompany', payload)
    },
  },
  actions: {
  },
  getters: {
    // 定义一个getters
    formatown_door (state) {
      return state.own_door
    },
    userID (state) {
      return state.userID
    },
    userName(state){
      return state.user_name
    },
    userEmail(state){
      return state.userEmail
    },
    my_portal_id(state){
      return state.my_portal_id
    },
    portal_id(state){
      return state.portal_id
    },
    isLogin(state){
      return state.isLogin
    },
    isCompany(state){
      return state.isCompany
    },
  },
  modules: {
  }
})
